package com.czh.springboot04.MyController;

import com.czh.springboot04.entity.Publicity;
import com.czh.springboot04.service.PublicityService;
import com.czh.springboot04.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("publicity")
public class PublicityController {
    @Autowired
    private PublicityService publicityService;
    @PostMapping("publicityAdd")
    public R publicityAdd(Publicity prublicity){
        int i = publicityService.publicityAdd(prublicity);
        if (i>0){
            return R.ok(i);
        }else{
            return R.fail("添加失败");
        }
    }
    @PutMapping("publicityUpdate")
    public R publicityUpdate(Publicity prublicity){
        int i = publicityService.publicityUpdate(prublicity);
        if (i>0){
            return R.ok(i);
        }else{
            return R.fail("修改失败");
        }
    }
    @DeleteMapping("publicityeDelete")
    public R publicityeDelete(int id){
        int i = publicityService.publicityeDelete(id);
        if (i>0){
            return R.ok(i);
        }else{
            return R.fail("删除失败");
        }
    }
    @GetMapping("publicitySelectAll")
    public R publicitySelectAll(int pageNum, int pageSize){
        PageInfo<Publicity> publicities = publicityService.publicitySelectAll(pageNum,pageSize);
        if (publicities!=null){
            return R.ok(publicities);
        }else
        {
            return R.fail("查询失败");
        }
    }
}
